<?php $this->load->view('header'); ?>
<div class="wrap-detail-project wrap-dashboard">
    <div class="container container-dashboard">
        <div class="row menu-parent-dashboard">
            <?php
            $this->load->view('sideBlocks/menuDashboard',$menuActive)?>
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 no-padding">
                <div class="search-dashboard">
                    <form action="" method="post" id="frm-search">
                        <select name="search_type" class="search-type">
                            <option>Client</option>
                            <option>Job</option>
                        </select>
                        <input type="text" name="search" class="search"
                               placeholder="<?php echo $this->lang->line('Find client'); ?>">
                        <button type="submit" class="btn-search glyphicon glyphicon-search"></button>
                    </form>
                </div>
            </div>
        </div>
        <div class="row">

                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding">
                    <ul class="nav nav-pills tab-child" role="tablist">
                        <li class="active"><a href="<?php echo url_buyerEditProfile();?>"><?php echo $this->lang->line("Profile")?></a></li>
                        <li><a href="<?php echo url_accountSettings()?>"><?php echo $this->lang->line("My account")?></a></li>
                        <li><a href="#settings" role="tab" data-toggle="tab"><?php echo $this->lang->line("Setting")?></a></li>

                    </ul>
                </div>

        </div>
        <div class="tab-content">
            <?php if(validation_errors() != null){?>
                <div class="alert alert-danger">
                    <button data-dismiss="alert" class="close"></button>
                    <i class="fa fa-times-circle"></i>
                    <strong><?php echo $this->lang->line('Message')?></strong>
                    <ul>
                        <?php echo validation_errors('<li>', '</li>'); ?>

                    </ul>
                </div>
            <?php } ?>
            <?php
                if($this->session->flashdata('edit_profile_success')) {
            ?>
            <div class="alert alert-success">
                <button data-dismiss="alert" class="close"></button>
                <i class="fa fa-times-circle"></i>
                <strong><?php echo $this->lang->line('Message')?></strong>
                <ul>
                    <?php
                    echo "<li>".$this->session->flashdata('edit_profile_success')."</li>";
                    ?>
                </ul>
            </div>
            <?php } ?>


            <div class="row app-panel tab-pane fade active in profile" id="profile">
                <?php echo form_open('buyer/editProfileUpdate');?>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-3 control-label">Title</label>
                    <div class="col-sm-9">
                        <?php echo form_input(array('class' => 'form-control','name' => 'title','value' => set_value('title',$user_info['title'])))?>
                    </div>

                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-3 control-label">Portrait</label>
                    <div class="col-sm-9">
                        <div class="col-lg-4">
                            <div id="cropContainerModal" style="background:url('<?php if ( (is_file_exists($user_info['logo'],'thumbs_logos') == TRUE ) && ($user_info['logo'] != "")) echo base_url().'files/thumbs_logos/'.$user_info['logo']; else echo image_default();?>')"></div>
                        </div>
                        <div class="col-lg-12">
                            <p>You need a photo!</p>
                            <p>Freelancers with a friendly,professional-looking portrait are hired 5 times more often than those  without a photo</p>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-3 control-label">Overview</label>
                    <div class="col-sm-9">
                        <?php echo form_textarea(array('class' => 'form-control','rows' => 3,'name' => 'profile_desc','value' => set_value('profile_desc',$user_info['profile_desc'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-3 control-label">Categories</label>
                    <div class="col-sm-9" id="ChildCategoryProfile">
                        <?php
//                        $group_parent[''] = $this->lang->line("Please select");
//                        foreach ($groupParent->result() as $item) {
//                            $group_parent[$item->id] = $item->group_name;
//                        }
//                        if($user_info['group_ids'] != ""){
//                            $list_group_ids = $user_info['group_ids'];
//                        }else{
//                            $list_group_ids = 0;
//                        }
//
//                        echo form_dropdown('group_parent', $group_parent, set_value('group_parent',$user_info['group_id']), 'id="ParentCategory" class="form-control" ');
//                        ?>
                        <?php
                            if(count($listParentCategories) > 0){ $dem = 0;
                                foreach($listParentCategories as $item) { $dem++
                        ?>
                        <section class="jsCategory">
                            <p><?php echo $item['name']?></p>
                            <?php
                            if( (isset($item['child']) == TRUE ) &&    count($item['child']) > 0) {
                                $arrayGroupUser = explode(',',$user_info['group_ids']);
                                foreach ($item['child'] as $item_child) {
                                    if(in_array($item_child['id'],$arrayGroupUser))
                                        $check = "checked";
                                    else
                                        $check = "";

                            ?>
                            <label class="child-category-profile control-label"><input name="group_ids[]" <?php echo $check;?> type="checkbox" <?php echo set_checkbox('group_ids',$item_child['id'])?> value="<?php echo $item_child['id']?>" >&nbsp;<?php echo $item_child['name']?>&nbsp;</label>
                            <?php } } ?>
                        </section>
                        <?php if($dem % 3 == 0) {?><div class="clear"></div> <?php } ?>
                        <?php } } ?>
                    </div>
                </div>
                <div class="form-group">
                    <div id="ChildCategoryProfile" class="child-category-profile col-lg-offset-3 col-lg-9 col-sm-12 col-md-12 col-xs-12 no-padding form-group child-category">
<!--                        --><?php
//                            if (isset($groupSelect)) {
//                                foreach ($groupSelect as $item) {
//                                    $arrayGroupUser = explode(",",$user_info['group_ids']);
//                                    print_r($arrayGroupUser);exit;
//                                    if(in_array($item['id'],$arrayGroupUser))
//                                        $selected = true;
//                                    else
//                                        $selected = false;
//
//                                    echo "<label class='label-category'>";
//                                    if ($selected == true) {
//                                        echo "<input type='checkbox' name='group[]' checked value='" . $item['id'] . "' />";
//                                    } else {
//                                        echo "<input type='checkbox' name='group[]' value='" . $item['id'] . "' />";
//                                    }
//                                    echo $item['group_name'] . "</label>";
//                                }
//                            }
//                            echo form_error('group');
//                        ?>

                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-3 col-lg-3 control-label">Skills</label>
                    <div class="col-sm-9 col-lg-9̣ list-skill">
                        <?php //echo form_input(array('class' => 'form-control','name' => 'user_categories','id' => 'user_categories'));?>
                        <select id="skills" data-placeholder="Select skills..." style="display: none;" multiple="" name="project_categories[]" class="chosen-select form-control">
                            <?php
                            //if($categories->num_rows() > 0){
                                //foreach ($categories->result() as $item){
                                    //if(array_search($item->id, $categoriesSelect)){
                                        //echo "<option value='".$item->id."' selected>".$item->category_name."</option>";
                                    //}else{
                                        //foreach($categoryGroups->result() as $category){
                                           // if($category->id == $item->id){
                                               // echo "<option value='".$item->id."'>".$item->category_name."</option>";
                                           // }
                                       // }
                                    //}
                               // }
                            //}
                            ?>

                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div id="stick-skills" class="col-lg-offset-3 col-lg-9 skills-profile">
                        <?php
                            if(count($categories) > 0){
                                echo "<ul>";
                                foreach($categories->result() as $item){
                                    if(count($userCategories) > 0) {
                                        $arrayUserCategories = explode(',', $userCategories['user_categories']);
                                        if (in_array($item->id, $arrayUserCategories)) {
                                            ?>
                                            <li class="label-skill" data-value="<?php echo $item->id?>"><?php echo $item->category_name;?></li>
                                        <?php
                                        }
                                    }
                                }
                                echo "</ul>";
                            }
                        ?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 col-sm-3 control-label"><?php echo $this->lang->line('Certificate');?></label>
                    <div class="col-lg-7 col-sm-3">
                        <input type="text" id="resume" class="form-control" />
                    </div>
                    <div class="col-lg-2">
                        <button type="button" id="add-resume" onclick="editResume()" class="btn btn-primary"><?php echo $this->lang->line('Add info') ?></button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-offset-3 col-lg-9">
                    <ul class="list-resume">
                        <?php
                        if ($user_info['resume'] != "") {
                            $user_resume = unserialize($user_info['resume']);
                            if (is_array($user_resume)) {
                                foreach ($user_resume as $resume) {
                                    ?>
                                    <li><span><?php echo $resume; ?><a class="del_resume" data-title="<?php echo $resume?>">Delete</a></span></li>
                                <?php
                                }
                            }
                        }
                        ?>
                    </ul>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-3 control-label">Years of Experience</label>
                    <div class="col-lg-9">
                        <?php
                            $year_experience = array(0,1,2,3,4,5,6,7,8,9,10);
                        echo form_dropdown('year_experience',$year_experience,set_value('year_experience',$user_info['year_exp']),'class = "form-control"');
                        ?>

                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 col-sm-3 control-label">Employment History</label>
                    <div class="col-lg-7 col-sm-3">
                        <input type="text" id="emp-history" class="form-control" />
                    </div>
                    <div class="col-lg-2">
                        <button type="button" id="add-emp-his" onclick="editEmpHis()" class="btn btn-primary"><?php echo $this->lang->line('Add info') ?></button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-offset-3 col-lg-9">
                        <ul class="list-emp-his">
                            <?php
                            if ($user_info['employment_history'] != "") {
                                $emp_his = unserialize($user_info['employment_history']);
                                if (is_array($emp_his)) {
                                    foreach ($emp_his as $item_emp_his) {
                                        ?>
                                        <li><span><?php echo $item_emp_his; ?><a class="del-emp-his" data-title="<?php echo $item_emp_his?>">Delete</a></span></li>
                                    <?php
                                    }
                                }
                            }
                            ?>
                        </ul>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">Portfolio</label>
                    <div class="col-lg-9">
                        <button type="button" class="btn btn-primary" id="add_portfolio">Add</button>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-offset-1 col-lg-11 control-label" style="text-align: left">Social networks</label>

                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">Facebook</label>
                    <div class="col-lg-9">
                        <?php echo form_input(array('class'=>'form-control','name' => 'facebook','value' => set_value('facebook',$user_info['facebook'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">Twitter</label>
                    <div class="col-lg-9">
                        <?php echo form_input(array('class'=>'form-control','name' => 'twitter','value' => set_value('twitter',$user_info['twitter'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">G+</label>
                    <div class="col-lg-9">
                        <?php echo form_input(array('class'=>'form-control','name' => 'google_plus','value' => set_value('google_plus',$user_info['google_plus'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">LinkedIn</label>
                    <div class="col-lg-9">
                        <?php echo form_input(array('class'=>'form-control','name' => 'linkedin','value' => set_value('linkedin',$user_info['linkedin'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">Github</label>
                    <div class="col-lg-9">
                        <?php echo form_input(array('class'=>'form-control','name' => 'github','value' => set_value('github',$user_info['github'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-lg-3 control-label">Your website</label>
                    <div class="col-lg-9">
                        <?php echo form_input(array('class'=>'form-control','name' => 'your_website','value' => set_value('your_website',$user_info['your_website'])));?>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-offset-3 col-lg-9">
                    <button type="submit" value="submit" name="submit" class="btn btn-primary">Public Views Of Profile</button>
                    <button type="submit" value="submit" name="submit" class="btn btn-primary">Update</button>
                    </div>
                </div>
                <?php echo form_close();?>
           </div><!--  profile-->
            <div class="row app-panel tab-pane fade" id="my-account">
                    My account
            </div><!--  my account -->
            <div class="row app-panel tab-pane fade" id="settings">
                    Settings
            </div><!--  notification  -->
        </div>
    </div>
</div>
    <div class="modal fade modal-image-user-profile" tabindex="-1" role="dialog"
    aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button data-dismiss="modal" class="close" type="button"><span
                        aria-hidden="true">×</span><span class="sr-only">Close</span>
                </button>
                <h4 id="mySmallModalLabel"
                    class="modal-title"><?php echo $this->lang->line('Edit Profile Picture') ?></h4>
            </div>
            <div style="text-align: center;">
                <form id="frm-image-user" method="POST" name="frm-image-user"
                      enctype='multipart/form-data'>
                    <div class="fileinput fileinput-new input-image-avatar-user"
                         data-provides="fileinput">
                        <div class="fileinput-preview thumbnail"
                             data-trigger="fileinput"
                             style="width: 200px; height: 150px;"></div>
                        <div>
                                                            <span class="btn btn-default btn-file"><span
                                                                    class="fileinput-new">Select image</span><span
                                                                    class="fileinput-exists">Change</span>
                                                                <input type="file" name="image"></span>
                            <a href="#" class="btn btn-default fileinput-exists"
                               data-dismiss="fileinput">Remove</a>
                        </div>
                    </div>
                    <div>
                        <div id="loading-image loading-image-2" style="display: none">
                            <img src="<?php echo image_url('loading.gif') ?>"/>
                        </div>
                        <button style="width: 65%;margin-bottom: 40px;" type="submit"
                                class="btn btn-success"><?php echo $this->lang->line('Set as Profile Picture') ?></button>
                    </div>
                </form>
                <script>
                    // var form = document.forms.namedItem("frm-image-user");

                    // form.addEventListener('submit', function (ev) {
                    //     var oData = new FormData(document.forms.namedItem("frm-image-user"));
                    //     var oReq = new XMLHttpRequest();
                    //     oReq.open("POST", '<?php echo base_url()."index.php/users/editImageProfile"?>', true);
                    //     oReq.onload = function (oEvent) {
                    //         if (oReq.status == 200) {
                    //             //location.reload();
                    //         } else {
                    //             console.log("Error " + oReq.status + " occurred uploading your file.<br \/>");
                    //         }
                    //     };

                    //     oReq.send(oData);
                    //     ev.preventDefault();
                    // }, false);
                </script>
            </div>
        </div>
    </div>
    </div>

<div class="modal fade bs-example-modal-lg" id="myModalAddPortfolio" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">Add Portfolio</h4>
            </div>
            <div class="modal-body bg_modal_addPortfolio">
                <?php $this->load->view('buyer/addPortfolio');?>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script src="<?php echo base_url() ?>app/js/croppic.min.js"></script>
<script>
    var croppicContainerModalOptions = {
        uploadUrl:'<?php echo site_url("buyer/img_save_to_file");?>',
        cropUrl:'<?php echo site_url("buyer/img_crop_to_file");?>',
        modal:true,
        imgEyecandyOpacity:0.4,
        loaderHtml:'<div class="loader bubblingG"><span id="bubblingG_1"></span><span id="bubblingG_2"></span><span id="bubblingG_3"></span></div> '
    }
    var cropContainerModal = new Croppic('cropContainerModal', croppicContainerModalOptions);
</script>
<script>
    var html = "";
    <?php
        if(count($categories) > 0){
            foreach($categories->result() as $item){
                if(count($userCategories) > 0) {
                    $arrayUserCategories = explode(',', $userCategories['user_categories']);
                    if (in_array($item->id, $arrayUserCategories)) {
    ?>
        html += "<option selected value='<?php echo $item->id?>'><?php echo $item->category_name;?></option>";
    <?php
                }
            }
        }
    }
    ?>
    $("#skills").append(html);
    $("#skills").trigger('liszt:updated');
    function editResume() {
        var resume = $("#resume").val();
        $.ajax({
            type: "POST",
            url: "<?php echo base_url()."index.php/users/editResume"?>",
            data: "value="+resume,
            beforeSend: function () {
                $('#loading-image').show();
            },
            success: function (data) {
                $('#loading-image').hide();
                data = $.parseJSON(data);
                if (data.status == 'error') {
                    $('#error-resume').html(data.message);
                } else {
                    var cList = $('.list-resume');
                    $('.btn-resume li span#error-resume').empty();
                    cList.empty();
                    $.each(data.data, function (i, item) {
                        var li = $('<li>').prependTo(cList);
                        var span = $('<span>').text(data.data[i]).prependTo(li);
                        var link = $("<a class='del_resume'>").attr('data-title',data.data[i]).text('Delete').prependTo(span);
                    });
                }
            }
        });
    }
    $(document).on("click","a.del_resume",function(){
        var resume = $(this).data("title");
        $.ajax({
            type: "POST",
            url: "<?php echo base_url()."index.php/users/deleteResume"?>",
            // có time sửa lại chuyển lên và nhận xuống đều là Json String
            data: "resume="+resume,
            beforeSend: function () {
                $('#loading-image').show();
            },
            success:function(data){
                $('#loading-image').hide();
                data = $.parseJSON(data);
                if (data.status == 'error') {
                    $('#error-resume').html(data.message);
                } else {
                    var cList = $('.list-resume');
                    $('.btn-resume li span#error-resume').empty();
                    cList.empty();
                    $.each(data.data, function (i, item) {
                        var li = $('<li>').prependTo(cList);
                        var span = $('<span>').text(data.data[i]).prependTo(li);
                        var link = $("<a class='del_resume'>").attr('data-title',data.data[i]).text('Delete').prependTo(span);
                    });
                }
            }
        });
    });
    function editEmpHis() {
        var resume = $("#emp-history").val();
        $.ajax({
            type: "POST",
            url: "<?php echo base_url()."index.php/users/editEmpHis"?>",
            data: "value="+resume,
            beforeSend: function () {
                $('#loading-image').show();
            },
            success: function (data) {
                $('#loading-image').hide();
                data = $.parseJSON(data);
                if (data.status == 'error') {
                    $('#error-resume').html(data.message);
                } else {
                    var cList = $('.list-emp-his');
                    $('.btn-resume li span#error-resume').empty();
                    cList.empty();
                    $.each(data.data, function (i, item) {
                        var li = $('<li>').prependTo(cList);
                        var span = $('<span>').text(data.data[i]).prependTo(li);
                        var link = $("<a class='del-emp-his'>").attr('data-title',data.data[i]).text('Delete').prependTo(span);
                    });
                }
            }
        });
    }
    $(document).on("click","a.del-emp-his",function(){
        var resume = $(this).data("title");
        $.ajax({
            type: "POST",
            url: "<?php echo base_url()."index.php/users/deleteEmpHis"?>",
            // có time sửa lại chuyển lên và nhận xuống đều là Json String
            data: "resume="+resume,
            beforeSend: function () {
                $('#loading-image').show();
            },
            success:function(data){
                $('#loading-image').hide();
                data = $.parseJSON(data);
                if (data.status == 'error') {
                    $('#error-resume').html(data.message);
                } else {
                    var cList = $('.list-emp-his');
                    $('.btn-resume li span#error-resume').empty();
                    cList.empty();
                    $.each(data.data, function (i, item) {
                        var li = $('<li>').prependTo(cList);
                        var span = $('<span>').text(data.data[i]).prependTo(li);
                        var link = $("<a class='del-emp-his'>").attr('data-title',data.data[i]).text('Delete').prependTo(span);
                    });
                }
            }
        });
    });

    $(document).on("click","#show-modal-crop-image",function(e){
        e.preventDefault();
        //var current_url = $(location).attr('href');
        $(location).attr('href',"<?php echo site_url('buyer/showPageCropPhoto')?>");

    })

    $(document).on('click','#add_portfolio',function(e){
        e.preventDefault();
        $('#myModalAddPortfolio').modal('show');
    });


</script>
<?php $this->load->view('footer'); ?>